<?php
namespace addons\wanlshop\library\WanlSdk;

use think\Exception;

class Common
{
	/**
	 * Redis连接
	 */
	public static function redis() 
	{
		if (!extension_loaded('redis')) {
			throw new Exception("服务器不支持Redis，请安装Redis和php redis拓展");
		}
		$config = get_addon_config('wanlshop');
		$redis = new \Redis;
		if ($config['redis']['persistent'] == 'Y') {
		    $redis->pconnect($config['redis']['host'], $config['redis']['port'], $config['redis']['timeout'], 'persistent_id_' . $config['redis']['select']);
		} else {
		    $redis->connect($config['redis']['host'], $config['redis']['port'], $config['redis']['timeout']);
		}
		if ('' != $config['redis']['password']) {
		    $redis->auth($config['redis']['password']);
		}
		if (0 != $config['redis']['select']) {
		    $redis->select($config['redis']['select']);
		}
		return $redis;
	}
	
}
